<template>
	<view class="uni_box home">
		<!-- <navbar title='课程中心'>
		</navbar> -->
		<Nheader></Nheader>
		<view class="content">
			<u-sticky :offset-top="BarHeight()" h5-nav-height="44">
				<view class="xuanview">
					<view class="xuanitem xactive" @click="isshai=true">
						<text class="qtit">{{ keinfo.name?keinfo.name:'全部' }}</text>
						<image class="xia" src="@/pages_subject/static/img/xia.png" mode="" />
						<image class="xias" src="@/pages_subject/static/img/xias.png" mode="" />
					</view>
					<view class="xuanitem" @click="pxshow=true">
						<text class="qtit">{{paiinfo.name?paiinfo.name:'推荐排序'}}</text>
						<image class="xia" src="@/pages_subject/static/img/xia.png" mode="" />
						<image class="xias" src="@/pages_subject/static/img/xias.png" mode="" />
					</view>
				</view>
				<view class="shaiview" v-if="isshai">
					<view class="shaiitem">
						<text class="shaitit">科目</text>
						<view class="shailist">
							<view class="shais" :class="keinfo.name==item.name?'sactive':''" v-for="(item,index) in kedata" :key="index" @click="keClick(item)">{{item.name}}</view>
						</view>
					</view>
					<view class="shaiitem" v-if="jidata!=''">
						<text class="shaitit">级别</text>
						<view class="shailist">
							<view class="shais" :class="jiinfo.name==item.name?'sactive':''" v-for="(item,index) in jidata" :key="index" @click="jiClick(item)">{{item.name}}</view>
						</view>
					</view>
					<view class="chongview">
						<view class="czhi" @click="chongzhi">重置</view>
						<view class="que" @click="popqueren">确认</view>
					</view>
				</view>
			</u-sticky>
			<view class="list">
				<view class="tilist-jiaocai" v-if="leitype == 1">
					<view class="tiitem-two" v-for="(item,index) in list" :key="index" @click="getDetail(item)">
						<image :src="item.image" class="itemimg" mode=""></image>
						<view class="itembot">
							<text class="tbiao txt">{{ item.title }}</text>
							<!-- <text class="timiao">Kaplan名师+配套notes精讲</text> -->
							<view class="linview">
								<text class="jine">¥<text class="jinnum">{{item.price}}</text></text>
								<text class="mian">{{item.buy_nums}}人已购买</text>
							</view>
						</view>
					</view>
				</view>
				<view class="tilist-jiaocai" v-if="leitype == 2">
					<view class="tiitem-two" v-for="(item,index) in list" :key="index" @click="getDetail(item)">
						<image :src="item.image" class="itemimg" mode=""></image>
						<view class="itembot">
							<text class="tbiao txt">{{ item.title }}</text>
							<text class="timiao">{{item.subtitle}}</text>
							<view class="linview">
								<text class="jine">¥<text class="jinnum">{{item.price}}</text></text>
								<view class="gmai">立即购买</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<u-select v-model="pxshow" :list="paidata" label-name="name" value-name="id" @confirm="pxconfirm"></u-select>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swlist: [{
						image: '/static/banner.png',
					},
					{
						image: '/static/banner.png',
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
					}
				],
				tablist: [{
					name: '商品详情'
				}, {
					name: '视频'
				}, {
					name: '交易规则'
				}],
				list: [],
				page: 1,
				limit: 10,
				last_page: 1,
				status: "loadmore",
				current: 0,
				isshai:false,
				jidata:[],//级别
				jiinfo:{
					id:''
				},//级别信息
				kedata:[],//科目
				keinfo:{
					id:''
				},
				paidata:[],
				paiinfo:{
					name:'',
					id:''
				},
				pxshow:false,
				leitype:1,//1课程中心 2图书中心
				id:'',//传入的分类ID
			}
		},
		onLoad(option) {
			if(option.leitype){
				this.leitype = option.leitype
			}
			if(option.id){
				this.id = option.id
			}
			// var statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			// console.log(this.BarHeight)
			// var navigationBarHeight = 100; // 假设导航栏高度是100像素
			// var overallHeight = statusBarHeight + navigationBarHeight;
			this.getinit();
			
		},
		onShow() {
		},
		onReachBottom: function () {
			this.loadmore();
		},
		methods: {
			getinit(){
				this.fgetLevelList();//级别
				this.fgetCateList();//科目
				this.fgetSortList();//排序
			},
			async fgetLevelList(){
				let res = await this.$u.api.getLevelList({
				});
				this.jidata = res
				// this.jidata = res
			},
			async fgetCateList(){
				let res = await this.$u.api.getCateList({
				});
				this.kedata = res
				if(this.id){
					let data = res
					for(let i in data){
						if(data[i].id == this.id){
							this.keinfo = data[i]
						}
					}
				}
				this.getList()
				// this.jidata = res
			},
			async fgetSortList(){
				let res = await this.$u.api.getSortList({
				});
				this.paidata = res
				// this.jidata = res
			},
			
			change(index) {
				this.current = index;
			},
			jiClick(item){
				this.jiinfo = item
				// this.getClear()
			},
			keClick(item){
				this.keinfo = item
				
				// this.getClear()
			},
			getClear(){
				this.list = []
				this.page = 1,
				this.status= "loadmore"
				this.getList()
			},
			async getList(){
				if(this.leitype == 1){
					//课程
					let res = await this.$u.api.getComboList({
						cate_id:this.keinfo.id,
						level_id:this.jiinfo.id,
						sort_id:this.paiinfo.id,
						page:this.page
					});
					this.last_page = res.lastpage;
					let list = res.list;
					this.list = this.page == 1 ? list : [...this.list, ...list];	
					if(this.page >= this.last_page){
					this.status = 'nomore';
					}
				}else if(this.leitype == 2){
					//图书
					let res = await this.$u.api.tugetBookList({
						cate_id:this.keinfo.id,
						level_id:this.jiinfo.id,
						sort_id:this.paiinfo.id,
						page:this.page
					});
					this.last_page = res.lastpage;
					let list = res.list;
					this.list = this.page == 1 ? list : [...this.list, ...list];	
					if(this.page >= this.last_page){
					this.status = 'nomore';
					}
				}
				
			},
			loadmore() {
				let page = this.page;
				// let last_page = this.last_page;
				if (this.status == 'loadmore') {
					this.page++;
					this.getList();
				}
			},
			pxconfirm(e){
				// console.log(e)
				this.paiinfo.id = e[0].value
				this.paiinfo.name = e[0].label
				this.getClear()
			},
			chongzhi(){
				this.keinfo = {
					id:''
				}
				this.jiinfo = {
					id:''
				}
				this.isshai = false
			},
			popqueren(){
				this.getClear()
				this.isshai = false
			},
			getDetail(item){
				if(this.leitype == 1){//课程详情
					this.navrouter("/pages_subject/twoPage/StudPage/KeDetail?id="+item.id);
				}else if(this.leitype==2){//图书详情
					this.navrouter("/pages_subject/twoPage/StudPage/ShuDetail?id="+item.id);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.content{
		background-color: #fff;
		// padding-bottom: 150rpx;
		.xuanview{
			height: 88rpx;
			position: relative;
			display: flex;
			flex-direction: row;
			border-top: 1rpx solid #eee;
			background-color: #fff;
			z-index: 100;
			.xuanitem{
				width: 50%;
				height: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				.qtit{
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #111111;
				}
				.xia{
					width: 11rpx;
					height: 6rpx;
					margin-left: 10rpx;
				}
				.xias{
					width: 11rpx;
					height: 6rpx;
					margin-left: 10rpx;
					display: none;
				}
			}
			.xactive{
				.qtit{
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #FA4E4E;
					
				}
				.xia{
					width: 11rpx;
					height: 6rpx;
					margin-left: 10rpx;
					display: none;
				}
				.xias{
					width: 11rpx;
					height: 6rpx;
					margin-left: 10rpx;
					display: inline-block;
				}
			}
		}
		.shaiview{
			padding: 25rpx 30rpx;
			background-color: #fff;
			display: flex;
			flex-direction: column;
			position: fixed;
    		width: 100%;
			z-index: 100;
			.shaiitem{
				margin-bottom: 20rpx;
				.shaitit{
					display: block;
					margin-bottom: 24rpx;
					font-family: PingFangSC;
					font-weight: bold;
					font-size: 24rpx;
					color: #333333;
				}
				.shailist{
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					.shais{
						width: 31%;
						margin-right: 2%;
						height: 64rpx;
						background: #F8F8F8;
						border-radius: 32rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						margin-bottom: 25rpx;
						font-weight: 500;
						font-size: 22rpx;
						color: #333333;
					}
					.sactive{
						background: #FFF0F0;
						color: #FA4E4E;
					}
				}
			}
			.shaiitem:last-child{
				margin-bottom: 0 !important;
			}
			
			.chongview{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: space-between;
				.czhi{
					width: 48%;
					height: 80rpx;
					background: #F8F8F8;
					border-radius: 40rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #111111;
				}
				.que{
					width: 48%;
					height: 80rpx;
					background: linear-gradient(-90deg, #FA4E4E, #FD894F);
					border-radius: 40rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #fff;
				}
			}
		}

		.list{
			padding: 0 30rpx;
		}
		.tilist-jiaocai{
		// margin-top: 40rpx;
		.tiitem-two{
			display: flex;
			flex-direction: row;
			background: #FFFFFF;
			border-radius: 10rpx;
			// padding: 20rpx;
			padding: 0rpx 0 30rpx;
			margin-bottom: 30rpx;
			border-bottom: 1rpx solid #eee;
			.itemimg{
				width: 260rpx;
				height: 160rpx;
				background: #F8F8F8;
				border-radius: 10rpx;
				margin-right: 20rpx;
			}
			.itembot{
				flex: 1;
				display: flex;
				flex-direction: column;
				.tbiao{
					max-width: 100%;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #111111;
					display: inline-block;
				}
				.timiao{
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					display: inline-block;
					margin-top: 20rpx;
				}

				.linview{
					display: flex;
					margin-top: auto;
					flex-direction: row;
					align-items: center;
					.jine{
						font-family: DIN;
						font-weight: bold;
						font-size: 20rpx;
						color: #FA4E4E;
						.jinnum{
							font-size: 32rpx;
						}
						
					}
					.mian{
						margin-left: auto;
						font-weight: 500;
						font-size: 20rpx;
						color: #CCCCCC;
					}
					.gmai{
						margin-left: auto;
						display: flex;
						align-items: center;
						justify-content: center;
						width: 130rpx;
						height: 52rpx;
						background: linear-gradient(-90deg, #FA4E4E, #FD894F);
						border-radius: 26rpx;
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 20rpx;
						color: #FFFFFF;
					}
				}
			}
		}
	}
	}
</style>
